package com.example.javabasic.suanfa.jiandan.找出数组元素数量大于一半;

/**
 * @description 找出数量多于一半的元素
 * @Author Lin FuYuan
 * @date 2020/10/15
 */
public class Solutation {



    public  int  test(int[] nums){
        int num = nums[0];
        int count = 1;
        for (int i = 1; i < nums.length; i++) {
            if(nums[i] == num){
                ++count;
            }else{
                if(--count ==0){
                    num = nums[i];
                    count = 1;
                }
            }
        }
        return num;
    }
}
